<style lang="less">
    @import "dealerApply.less";
</style>
<template>
    <div class="search">
        <div v-show="parentGroup" >
            <Row>
                <Col>
                    <Card>
                        <Row>
                            <Form ref="searchForm" :model="searchForm" inline :label-width="160" class="search-form">
                                <Row class="operation">
                                    <i-col span="8">
                                        <Form-item label="合作商名称" prop="channelFullName">
                                            <Input type="text" v-model="searchForm.channelFullName" clearable placeholder="请输入合作商名称"
                                                   style="width: 200px"/>
                                        </Form-item>
                                    </i-col>

                                    <i-col span="8">
                                        <Form-item label="上线起止日期" prop="onlineDate">
                                            <DatePicker v-model="selectDate" type="daterange" format="yyyy-MM-dd"
                                                        @on-change="selectDateRange" placeholder="选择起止时间"
                                                        style="width: 200px">
                                            </DatePicker>
                                        </Form-item>
                                    </i-col>
                                    <i-col span="8">
                                        <Form-item label="渠道归属" prop="channelBelong">
                                            <Select v-model="searchForm.channelBelong" placeholder="请选择" clearable style="width: 200px">
                                                <Option :value="item.value" v-for="(item,index) in channelBelongList" :key="index"> {{item.title}}</Option>
                                            </Select>
                                        </Form-item>
                                        <a class="drop-down" @click="dropDown">{{dropDownContent}}
                                            <Icon :type="dropDownIcon"></Icon>
                                        </a>
                                    </i-col>

                                    <span v-if="drop">
                                        <i-col span="8">
                                        <Form-item label="法人" prop="legalPerson">
                                          <Input type="text" v-model="searchForm.legalPerson" clearable placeholder="请输入法人名称"
                                                 style="width: 200px"/>
                                        </Form-item>
                                    </i-col>
                                    <i-col span="8">
                                        <Form-item label="授权区域" prop="authFegion">
                                            <Cascader v-model="selectAuthFegion" :data="authFegionDate"
                                                      @on-change="handleChangeAuthFegion" change-on-select filterable
                                                      placeholder="请选择" style="width: 200px;padding-top: 5px">
                                            </Cascader>
                                        </Form-item>
                                    </i-col>

                                    <i-col span="8">
                                         <FormItem label="注册省市" prop="channelAddress" >
                                              <Cascader :data="location" v-model="searchForm.addressinfo" @on-change="handleChannelAddress" change-on-select filterable style="width:200px;"
                                                        :load-data="loadData"></Cascader>
                                          </FormItem>

                                    </i-col>


                                    <i-col span="8">
                                        <Form-item label="合作商评级" prop="channelGrade">
                                            <Select v-model="searchForm.channelGrade" placeholder="请选择" clearable style="width: 200px">
                                                <Option value="1">A</Option>
                                                <Option value="2">B</Option>
                                                <Option value="3">C</Option>
                                                <Option value="4">D</Option>
                                            </Select>
                                        </Form-item>
                                    </i-col>

                                    <i-col span="8">
                                        <Form-item label="优质等级" prop="qualityGrade">
                                            <Select v-model="searchForm.qualityGrade" placeholder="请选择" clearable style="width: 200px">
                                                <Option :value="item.value" v-for="(item,index) in qualityGradeList" :key="index"> {{item.title}}</Option>
                                            </Select>
                                        </Form-item>
                                    </i-col>
                                </span>
                                </Row>
                                <Row  style="text-align: center">
                                    <Form-item style="margin-left:-60px; text-align: center" class="br">
                                        <Button @click="handleSearch" type="primary" icon="ios-search">查询</Button>
                                        <Button @click="handleReset" icon="md-redo">重置</Button>
                                    </Form-item>
                                </Row>
                            </Form>
                        </Row>
                        <Row class="operation">
                            <Button v-if="businessManage!=null||ownBusinessManage!=null" @click="editCustomerManager" type="primary" >批量修改区域经理</Button>
                            <Button v-if="businessManage!=null||ownBusinessManage!=null" @click="modifyRange" type="primary" >批量修改经纬度范围</Button>
                            <Button v-if="businessManage!=null||ownBusinessManage!=null" @click="afterArchive" type="primary" >贷后归档推送</Button>
                            <circleLoading v-if="operationLoading"/>
                        </Row>
                        <Row>
                            <Alert show-icon>
                                已选择 <span class="select-count">{{selectCount}}</span> 项
                                <a class="select-clear" @click="clearSelectAll">清空</a>
                            </Alert>
                        </Row>
                        <Row>
                            <Table :loading="loading" border :columns="columns" :data="data" sortable="custom"
                                   @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table">
                                <template slot-scope="{ row, index }" slot="channelFullName">
                                    <a  type="primary" size="small" @click="showChannelName(row)">{{row.channelFullName}}
                                    </a>
                                </template>
                                <template slot-scope="{ row, index }" slot="action">

                                <span v-if="(row.channelStatus =='00' || row.channelStatusOldCar =='00')">

                                        <span v-if=" ownBusinessManage =='03' || businessManage =='03' ">

                                            <span v-if=" row.channelBelong=='01'&& ownBusinessManage =='03'  ">
                                                 <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">维护</Button>
                                            </span>

                                            <span v-else-if=" row.channelBelong !='01'&& businessManage =='03'  ">
                                                <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">维护</Button>
                                            </span>

                                        </span>
                                        <span v-else>
                                            <!--拥有直营二手车权限（不等于01，等于02或者03）-->
                                            <span v-if=" row.channelBelong=='01'&& ownBusinessManage !='01' && ownBusinessManage!=null&& ownBusinessManage!=undefined&& ownBusinessManage!='' ">
                                                 <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">维护</Button>
                                            </span>

                                            <!-- 拥有非直营二手车权限（不等于01，等于02或者03）-->
                                            <span v-else-if=" row.channelBelong !='01'&& businessManage !='01' && businessManage!=null&& businessManage!=undefined&& businessManage!='' ">
                                                <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">维护</Button>
                                            </span>

                                            <!--拥有直营新车车权限（不等于02，等于01或者03）-->
                                            <span v-if=" row.channelBelong=='01'&& ownBusinessManage !='02' && ownBusinessManage!=null&& ownBusinessManage!=undefined&& ownBusinessManage!='' ">
                                                <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">维护</Button>
                                            </span>

                                            <!-- 拥有非直营新车权限（不等于02，等于01或者03）-->
                                            <span v-else-if=" row.channelBelong !='01'&& businessManage !='02' && businessManage!=null&& businessManage!=undefined&& businessManage!='' ">
                                                <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">维护</Button>
                                            </span>
                                        </span>
                                </span>

                                </template>

                                <template slot-scope="{ row, index }" slot="channelStatus">
                                    <span>{{setChannelStatusTitle(row.channelStatus)}}</span>
                                </template>
                                <template slot-scope="{ row, index }" slot="channelGrade">
                                    <span>{{setChannelGradeTitle(row.channelGrade)}}</span>
                                </template>
                                <template slot-scope="{ row, index }" slot="businessType">
                                    <span>{{setBusinessTypeTitle(row.businessType)}}</span>
                                </template>
                                <template slot-scope="{ row, index }" slot="customerManager">
                                    <span>{{setCustomerManagerTitle(row.customerManager)}}</span>
                                </template>
                                <template slot-scope="{ row, index }" slot="qualityGrade">
                                    <span>{{setQualityGradeTitle(row.qualityGrade)}}</span>
                                </template>
                                <template slot-scope="{ row, index }" slot="channelStatusOldCar">
                                    <span>{{setChannelStatusOldCarTitle(row.channelStatusOldCar)}}</span>
                                </template>
                                <template slot-scope="{ row, index }" slot="channelBelong">
                                    <span>{{setChannelBelongTitle(row.channelBelong)}}</span>
                                </template>

                                <!--翻译省市-->
                                <template slot-scope="{ row, index }" slot="address">
                                    <span>{{getDetailAddress(row.channelProvince,row.channelCity,row.channelAddress)}}</span>
                                </template>

                            </Table>
                        </Row>
                        <Row type="flex" justify="end" class="page">
                            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize"
                                  @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]"
                                  size="small" show-total show-elevator show-sizer></Page>
                        </Row>
                    </Card>
                </Col>
            </Row>
            <Modal :title="modalTitle" v-model="channelModalVisible" :mask-closable='false' :width="500" :styles="{top: '90px'}">

                <Form ref="channelForm" :model="channelForm" :label-width="100" :rules="channelFormValidate">
                    <FormItem label="渠道上线类型" prop="channelType">
                        <Select v-model="channelForm.channelType" placeholder="请选择" >
                            <Option value="00">SP</Option>
                            <Option value="01">直营</Option>
                            <Option value="02">总对总</Option>
                        </Select>
                    </FormItem>
                </Form>
                <div slot="footer">
                    <Button type="text" @click="cancelChannel">取消</Button>
                    <Button type="primary" @click="submitChannel">确认</Button>
                </div>
            </Modal>

            <Modal :title="modalTitle" v-model="channelRangeModalVisible" :mask-closable='false' :width="500" :styles="{top: '90px'}">
                <Form ref="LlRangeForm" :model="LlRangeForm" :label-width="100" :rules="channelRangeFormVisible">
                        <FormItem label="变更值(km)" prop="longitudeLatitudeRange">
                            <Input v-model.trim="LlRangeForm.longitudeLatitudeRange"  class="w300"  placeholder="请输入"/>
                        </FormItem>
                </Form>
                <div slot="footer">
                    <Button type="text" @click="cancelChannel">取消</Button>
                    <Button type="primary" @click="saveModifyRange">保存</Button>
                </div>
            </Modal>

            <Modal title="请选择修改后的区域经理" v-model="channelManagerModalVisible" :mask-closable='false' :width="400" :styles="{top: '100px'}">
                <Form  ref="managerForm" :model="managerForm">
                    <FormItem label="新车区域经理" prop="customerManager" style="widtht: 350px">
                        <Select v-model="managerForm.customerManager" placeholder="区域经理" filterable class="s1" style="widtht: 200px">
                            <Option v-for="(item,index) in regionalManagerNew" :value="item.userName" :label="item.userRealName" :key="index" >
                            </Option>
                        </Select>
                    </FormItem>
                    <FormItem label="二手车区域经理" prop="customerManagerOld" style="widtht: 350px">
                        <Select v-model="managerForm.customerManagerOld" placeholder="区域经理" filterable class="s1"  style="widtht: 200px">
                            <Option v-for="(item,index) in regionalManagerOld" :value="item.userName" :label="item.userRealName" :key="index" >
                            </Option>
                        </Select>
                    </FormItem>
                </Form>
                <div slot="footer" style="text-align:center;" >
                    <Button type="text" @click="cancelChannel">取消</Button>
                    <Button type="primary" @click="okSalesMan">提交</Button>
                </div>
            </Modal>
        </div>
    </div>
</template>
<script>

    //翻译省市
    import { getLocation } from "@/projects/afs-channel/api/common/common";

    import {
        getChannelListData,
        deleteChannel,
        saveModifyRange,
        saveModifyManager,
        afterArchive
    } from "@/projects/afs-channel/api/dealer/dealer";
    import {
        getAllAddressList,
        getRoleType,
        getAllRegionalManager
    } from "_p/afs-channel/api/common/common.js"

    import {getDictDataByType} from "_p/basic/api/admin/datadic";
    import {deepClone} from "../../../../libs/utils/ObjectClone";
    export default {
        name: "channelManage",
        components: {
        },
        data() {
            const validateAmount = (rule, value, callback) => {
                var reg = /^\d+(\.\d+)?$/;
                if(!value){
                    callback();
                    return;
                }
                if (!reg.test(value)) {
                    callback(new Error("数值类型格式错误"));
                } else {
                    callback();
                }

            };
            return {
                //省市
                province:[],
                city:[],
                location: [],
                //非直营权限：新车：01；二手车：02；新车and二手车：03
                businessTypeChannel:null,
                //直营权限：新车：01；二手车：02；新车and二手：03
                ownBusinessTypeChannel:null,

                //非直营管理权限：新车：01；二手车：02；新车and二手车：03
                businessManage: null,
                //直营管理权限：新车：01；二手车：02；新车and二手：03
                ownBusinessManage: null,

                //是否超级管理员账号
                isManage:null,

                parentGroup:true,//父页面默认展示
                loading: true,
                operationLoading: false,
                loadingExport: true,
                drop: false,
                dropDownContent: "更多",
                dropDownIcon: "ios-arrow-down",
                selectCount: 0,
                selectList: [],
                selectAuthFegion:[],
                authFegionDate:[],
                userModalVisible: false,
                expandLevel:0,
                //当前用户是否拥有新车权限：默认否
                isNewCarRole:"0",
                //当前用户是否拥有二手车权限：默认否
                isOldCarRole:"0",
                //新车合作商状态字典处理
                channelStatusList:[],
                //二手车合作商账号字典处理
                channelStatusOldCarList:[],
                //合作商评级字典处理
                channelGradeList:[],
                //业务类型字典处理
                businessTypeList:[],
                //客户经理字典处理
                customerManagerList:[],
                //优质等级字典处理
                qualityGradeList:[],
                //渠道归属
                channelBelongList:[],
                authFegion:[],
                //区域经理
                regionalManagerNew:[],
                //二手车区域经理
                regionalManagerOld:[],
                searchForm: {
                    pageNumber: 1,
                    pageSize: 10,
                    channelFullName: "",
                    channelStatus: "00",
                    legalPerson: "",
                    authRegion: "",
                    channelAddress:"",
                    channelBelong: "",
                    channel_grade:"",
                    quality_grade:"",
                    startDate: "",
                    endDate: "",
                    channelStatusOldCar:"00",

                    businessTypeChannel:"",
                    ownBusinessTypeChannel:"",
                    addressinfo: [],
                    channelCity:"",
                },
                selectDate: null,
                modalType: 0,
                channelModalVisible: false,
                channelRangeModalVisible:false,
                channelManagerModalVisible:false,
                modalTitle: "",
                channelForm: {
                    sex: 1,
                    type: 0,
                    channelType:"",
                },
                channelFormValidate: {
                    channelType: [
                        {required: true, message: "渠道上线类型不能为空", trigger: "blur"}
                    ],
                },
                LlRangeForm:{
                    longitudeLatitudeRange:"",
                },
                channelRangeFormVisible:{
                    longitudeLatitudeRange:[
                        { required: true, message: "经纬度范围不能为空", trigger: "blur"},
                        {validator: validateAmount, trigger: "blur"}
                    ],
                },
                managerForm:{

                },
                columns: [
                    {
                        type: "selection",
                        minWidth: 60,
                        maxWidth:60,
                        align: "center",
                        fixed: "left"
                    },
                    {
                        type: 'index',
                        title:"序号",
                        minWidth: 80,
                        align: "center",
                        fixed: "left"

                    },
                    {
                        title: "合作商名称",
                        key: "channelFullName",
                        minWidth: 120,
                        fixed: "left",
                        slot:"channelFullName"
                    },
                    {
                        title: "法人",
                        key: "legalPerson",
                        minWidth: 145
                    },
                    {
                        title: "上线日期",
                        key: "onlineDate",
                        minWidth: 150
                    },
                    {
                        title: "注册地址",
                        slot: "address",
                        align: "center",
                        minWidth: 250
                    },
                    {
                        title: "渠道归属",
                        key: "channelBelong",
                        minWidth: 115,
                        slot:"channelBelong"
                    },
                    {
                        title: "主营品牌",
                        key: "mainBrand",
                        minWidth: 180,
                        ellipsis:true,
                        render: (h, params) => {
                            return h('div', [
                                h('span', {
                                    style: {
                                        display: 'inline-block',
                                        width: '100%',
                                        overflow: 'hidden',
                                        textOverflow: 'ellipsis',
                                        whiteSpace: 'nowrap'
                                    },
                                    domProps: {
                                        title: params.row.mainBrand
                                    }
                                }, params.row.mainBrand)
                            ])
                        }
                    },

                    {
                        title: "业务属性",
                        key: "businessType",
                        minWidth: 150,
                        slot:"businessType"
                    },
                    {
                        title: "客户经理",
                        key: "customerManager",
                        minWidth: 150,
                        slot:"customerManager"
                    },
                    {
                        title: "合作商评级",
                        key: "channelGrade",
                        minWidth: 150,
                        slot:"channelGrade"
                    },
                    {
                        title: "优质等级",
                        key: "qualityGrade",
                        minWidth: 150,
                        slot:"qualityGrade"
                    },
                    {
                        title: "新车合作商状态",
                        key: "channelStatus",
                        minWidth: 140,
                        slot:"channelStatus"
                    },
                    {
                        title: "二手车合作商状态",
                        key: "channelStatusOldCar",
                        minWidth: 140,
                        slot:"channelStatusOldCar"
                    },
                    {
                        title: "操作",
                        key: "action",
                        minWidth: 200,
                        align: "center",
                        fixed: "right",
                        slot: "action"
                    }
                ],
                data: [],
                total: 0
            };
        },
        methods: {
            init() {
                //翻译省市
                this.getProvinceData();
                this.getCityData();
                this.getLocationData();

                this.getMainAreaList();
                this.initLabelType();
                this.getAllRegionalManager();
                this.getAllRegionalManagerNew();
                this.getAllRegionalManagerOld();
                this.getRole();
                this.getManage();
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getChannelList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getChannelList();
            },
            selectDateRange(v) {
                if (v) {
                    this.searchForm.startDate = v[0];
                    this.searchForm.endDate = v[1];
                }
            },
            getChannelList() {
                // 多条件搜索渠道列表
                this.loading = true;
                this.searchForm.channelCity =this.searchForm.addressinfo[1],
                getChannelListData(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.data = res.data.data.records;
                        this.total = res.data.data.total;
                    }
                });
            },

            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getChannelList();
            },
            handleReset() {
                this.selectCount=0;
                this.$refs.searchForm.resetFields();
                this.searchForm.addressinfo = [];
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                this.selectAuthFegion = [];
                this.searchForm.authFegion = "";
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getChannelList();
            },
            cancelChannel() {
                //关闭窗口
                this.channelModalVisible = false;
                this.channelManagerModalVisible = false;
                this.channelRangeModalVisible = false;
            },
            submitChannel (){
                this.$refs.channelForm.validate(valid => {
                    if (valid) {
                        let param={
                            //按钮是否隐藏：保存、提交、返回展示，黑名单隐藏
                            bottonView:0,
                            //信息是否只读:1 非只读
                            infoView:1,
                            //操作类型：0，新增
                            operationType:0,
                            //渠道归属新增的时候通过选择传值
                            channelType:this.channelForm.channelType,
                            isNewCarRole:this.isNewCarRole,
                            isOldCarRole:this.isOldCarRole
                        };
                        this.channelModalVisible = false;
                        this.afs.newTab(this,'projects/afs-channel/pages/dealer-apply/dealer-online/dealerIndex','信息录入','ios-add',param,"channelOnline-add",[],true)
                    }
                })
            },
            add() {
                if(this.isNewCarRole=="0" && this.isOldCarRole=="0"){
                    //表示当前用户既没有新车权限，也没有二手车权限
                    this.$Message.error("当前用户既无新车权限也无二手车权限，请维护后并刷新！");
                    return;
                }
                //新增页面
                this.modalType = 0;
                this.modalTitle = "             ";
                this.$refs.channelForm.resetFields();
                this.channelModalVisible = true;
            },
            edit(v) {
                let param={
                    //按钮是否隐藏：保存、提交、返回展示，黑名单隐藏
                    bottonView:0,
                    //信息是否只读:1 非只读
                    infoView:1,
                    //操作类型：1，修改
                    operationType:1,
                    //渠道id
                    channelId:v.id,
                    channelType:v.channelBelong,
                    isNewCarRole:this.isNewCarRole,
                    isOldCarRole:this.isOldCarRole,
                    channelStatus:v.channelStatus,
                    channelStatusOldCar:v.channelStatusOldCar,
                    officeProvince:"",
                    officeAddress:v.officeAddress,
                    businessType:v.businessType
                };
                if(param.channelStatus !="00"){
                    //根据渠道新车已启用状态判断是否拥有用户角色
                    param.isNewCarRole="0"
                }
                if(param.channelStatusOldCar !="00"){
                    //根据渠道二手车已启用状态判断是否拥有用户角色
                    param.isOldCarRole="0"
                }
                if(v.officeProvince!="" && v.officeCity!=""){
                    let province="";
                    let city="";
                    for(let i=0;i<this.province.length;i++){
                        if(this.province[i].value==v.officeProvince){
                            province=this.province[i].label;
                        }
                    };
                    for(let i=0;i<this.city.length;i++){
                        if(this.city[i].value==v.officeCity){
                            city=this.city[i].label;
                        }
                    };
                    param.officeProvince = province+city;
                }else{
                    param.officeProvince = '';
                }
                this.channelModalVisible = false;
                this.afs.newTab(this,'projects/afs-channel/pages/dealer-apply/dealer-online/dealerIndexModify','信息维护','ios-add',param,"channelOnline-modify"+v.id,[],true)
            },
            back() {
                this.parentGroup=true;
            },
            remove(v) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除 " + v.channelFullName + " ?",
                    onOk: () => {
                        this.operationLoading = true;
                        deleteChannel(v.id).then(res => {
                            this.operationLoading = false;
                            if (res.code === "0000") {
                                this.$Message.success("删除成功");
                                this.getChannelList();
                            }
                        });
                    }
                });
            },
            showChannelName(v){
                let param={
                    //按钮是否隐藏：保存、提交、隐藏，返回、黑名单展示
                    bottonView:1,
                    //信息是否只读:1 只读
                    infoView:0,
                    //操作类型：1，查看
                    operationType:2,
                    //渠道id
                    channelId:v.id,
                    isNewCarRole:this.isNewCarRole,
                    isOldCarRole:this.isOldCarRole
                };
                this.channelModalVisible = false;
                this.afs.newTab(this,'projects/afs-channel/pages/dealer-apply/dealer-online/dealerIndexModify','信息查看','ios-view',param,"channelOnlineModify-view"+v.id,[],true)

            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "更多";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            loadData(item, callback) {
                item.loading = true;
                getAllAddressList(item.value).then(res => {
                    item.loading = false;
                    if (res.code === "0000") {
                        res.data.forEach(function (e) {
                            if (e.isParent) {
                                e.value = e.id;
                                e.label = e.title;
                                e.loading = false;
                                e.children = [];
                            } else {
                                e.value = e.id;
                                e.label = e.title;
                            }
                        });
                        item.children = res.data;
                        callback();
                    }
                });
            },
            handleChangeAuthFegion(id, selectedData) {
                // 获取最后一个值
                if (id && id.length > 0) {
                    this.searchForm.authFegion = id[id.length - 1];
                } else {
                    this.searchForm.authFegion = "";
                }
            },
            handleChannelAddress(value, selectedData){
                // 获取最后一个值
                if (value && value.length > 0) {
                    this.searchForm.channelAddress = value[value.length - 1];
                } else {
                    this.searchForm.channelAddress = "";
                }
            },
            getMainAreaList(){
                getAllAddressList().then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        // 仅展开指定级数 默认一级
                        let expandLevel = this.expandLevel;
                        res.data.forEach(function (e) {
                            if (expandLevel == "0") {
                                if (e.addrLevel === "0") {
                                    e.expand = true;
                                    e.value=e.id;
                                }
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (c.addrLevel === "1") {
                                            c.expand = false;
                                            c.value=e.id;
                                        }
                                    });
                                }
                            } else {
                                if (e.children && e.children.length > 0) {
                                    e.children.forEach(function (c) {
                                        if (expandLevel == 1) {
                                            if (c.addrLevel === "1") {
                                                c.expand = false;
                                                c.value=e.id;
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        this.authFegionDate= res.data;
                    }
                });
            },

            //新车合作商状态
            setChannelStatusTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                this.channelStatusList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            //二手车合作商状态
            setChannelStatusOldCarTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                this.channelStatusOldCarList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },

            //渠道归属
            setChannelBelongTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                this.channelBelongList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },



            //评级：需区分新车评级，二手车评级
            setChannelGradeTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                let valTemp = val.split(',');
                if(valTemp.length>1){
                    let title ="";
                    for(let i in valTemp ){
                        this.channelGradeList.forEach(column => {
                            if(column.value === valTemp[i]){
                                dic = column;
                                title =title+"   "+dic.title;
                            }
                        });
                    }
                    return title
                }else{
                    let dic = {};
                    this.channelGradeList.forEach(column => {
                        if(column.value === val){
                            dic = column;
                        }
                    });
                    return dic.title;
                }
            },
            //业务类型处理
            setBusinessTypeTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                let valTemp = val.split(',');
                if(valTemp.length>1){
                    let title ="";
                    for(let i in valTemp ){
                        this.businessTypeList.forEach(column => {
                            if(column.value === valTemp[i]){
                                dic = column;
                                title =title+"  "+dic.title;
                            }
                        });
                    }
                    return title
                }else{
                    let dic = {};
                    this.businessTypeList.forEach(column => {
                        if(column.value === val){
                            dic = column;
                        }
                    });
                    return dic.title;
                }
            },

            //客户经理
            setCustomerManagerTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                let valTemp = val.split(',');
                if(valTemp.length>1){
                    let title =new Set();
                    for(let i in valTemp ){
                        this.customerManagerList.forEach(column => {
                            if(column.userName === valTemp[i]){
                                dic = column;
                                // title =title+"   "+dic.userRealName;
                                title.add(dic.userRealName)
                            }
                        });
                    }
                    return [...title].join(' ')
                }else{
                    let dic = {};
                    this.customerManagerList.forEach(column => {
                        if(column.userName === val){
                            dic = column;
                        }
                    });
                    return dic.userRealName;
                }
            },

            //优质等级
            setQualityGradeTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                let valTemp = val.split(',');
                if(valTemp.length>1){
                    let title ="";
                    for(let i in valTemp ){
                        this.qualityGradeList.forEach(column => {
                            if(column.value === valTemp[i]){
                                dic = column;
                                title =title+"   "+dic.title;
                            }
                        });
                    }
                    return title
                }else{
                    let dic = {};
                    this.qualityGradeList.forEach(column => {
                        if(column.value === val){
                            dic = column;
                        }
                    });
                    return dic.title;
                }
            },

            initLabelType(){
                let channelStatusDic="channelStatus";
                getDictDataByType(channelStatusDic).then(res =>{
                    if (res.code === "0000"){
                        this.channelStatusList = res.data;
                    }
                });

                let channelBelongDic="channelBelong";
                getDictDataByType(channelBelongDic).then(res =>{
                    if (res.code === "0000"){
                        this.channelBelongList = res.data;
                    }
                });

                let channelStatusOldDic="channelStatus";
                getDictDataByType(channelStatusOldDic).then(res =>{
                    if (res.code === "0000"){
                        this.channelStatusOldCarList = res.data;
                    }
                });

                let channelGradeDic="channelGrade";
                getDictDataByType(channelGradeDic).then(res =>{
                    if (res.code === "0000"){
                        this.channelGradeList = res.data;
                    }
                });

                let businessTypeDic="businessType";
                getDictDataByType(businessTypeDic).then(res =>{
                    if (res.code === "0000"){
                        this.businessTypeList = res.data;
                    }
                });

                let customerManagerDic="customerManager";
                getDictDataByType(customerManagerDic).then(res =>{
                    if (res.code === "0000"){
                        this.customerManagerList = res.data;
                    }
                });

                let qualityGradeDic="qualityGrade";
                getDictDataByType(qualityGradeDic).then(res =>{
                    if (res.code === "0000"){
                        this.qualityGradeList = res.data;
                    }
                });
            },

            // 查询数据字典
            initDataDic() {
                this.channelBelongType();
                this.channelStatusType();
                this.qualityGradeType();
            },
            //渠道归属数据字典
            channelBelongType() {
                let param = {
                    type: "channelBelong"
                }
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.channelBelongList = res.data;
                    }
                });
            },
            //渠道状态字典
            channelStatusType() {
                let param = {
                    type: "channelStatus"
                }
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.channelStatusList = res.data;
                    }
                });
            },

            //优质等级
            qualityGradeType() {
                let param = {
                    type: "qualityGrade"
                }
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.qualityGradeList = res.data;
                    }
                });
            },
            getAllRegionalManager(){
                //获取当前区域经理下面所有的业务人员
                let array =["ROLE_NEW_REG_MANAGER","ROLE_OLD_REG_MANAGER"];
                let customerManagerList = deepClone(this.customerManagerList)
                array.forEach(item =>{
                    getAllRegionalManager((item)).then(res => {
                        if (res.code === "0000") {
                            customerManagerList.push(...res.data.data);
                            this.customerManagerList=customerManagerList
                        }
                    });
                })
            },
            modifyRange() {
                if (this.selectCount <= 0) {
                    this.$Message.warning("您还未选择需要修改的数据");
                    return;
                }
                this.modalType = 0;
                this.modalTitle = "批量修改经纬度范围";
                this.$refs.LlRangeForm.resetFields();
                this.channelRangeModalVisible = true;
            },
            saveModifyRange(){
                this.$refs.LlRangeForm.validate(valid => {
                    if (valid) {
                        let ids = [];
                        this.selectList.forEach(function (e) {
                            ids.push(e.id);
                        });
                        let param={
                            channelIds:ids,
                            llRangeModify:this.LlRangeForm.longitudeLatitudeRange,
                        };
                        saveModifyRange(param).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("修改成功");
                                this.channelRangeModalVisible = false;
                                this.getChannelList();
                                this.selectCount=0;
                            }
                        });
                    }
                })
            },

            okSalesMan(){
                let ids = [];
                this.selectList.forEach(function (e) {
                    ids.push(e.id);
                });
                let param={
                    channelIds:ids,
                    customerManagerNew:this.managerForm.customerManager,
                    customerManagerOld:this.managerForm.customerManagerOld,
                };
                saveModifyManager(param).then(res => {
                    if (res.code === "0000") {
                        this.$Message.success("修改成功");
                        this.channelManagerModalVisible = false;
                        this.getChannelList();
                        this.selectCount=0;
                    }
                });
            },

            //新车区域经理
            getAllRegionalManagerNew(){
                //获取当前区域经理下面所有的业务人员
                getAllRegionalManager("ROLE_NEW_REG_MANAGER").then(res => {
                    if (res.code === "0000") {
                        this.regionalManagerNew=res.data.data;
                    }
                });
            },
            //二手车区域经理
            getAllRegionalManagerOld(){
                //获取当前二手车区域经理下面所有的业务人员
                getAllRegionalManager("ROLE_OLD_REG_MANAGER").then(res => {
                    if (res.code === "0000") {
                        this.regionalManagerOld=res.data.data;
                    }
                });
            },

            //批量修改业务员
            editCustomerManager() {
                if (this.selectCount <= 0) {
                    this.$Message.warning("您还未选择要修改的数据");
                    return;
                }
                this.modalType = 0;
                this.$refs.managerForm.resetFields();
                this.channelManagerModalVisible = true;
            },


            //调用省市的方法
            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                getLocation({upperCode: item.value}).then(res => {
                                    if (res.code === "0000") {
                                        item.children = res.data;
                                        this.location.push(item);
                                    }
                                })
                            }
                        })
                    }
                    // this.location.push(...res.data);
                })
            },
            loadData(item, callback) {
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },
            //反向解析省市地址
            getProvinceData() {
                let param = {level:"1",upperCode: "1"};
                getLocation(param).then(res => {
                    if(res.code === "0000"){
                        this.province=res.data;
                    }
                });
            },
            getCityData() {
                let param = {level:2,upperCode:''};
                getLocation(param).then(res => {
                    if (res.code == "0000") {
                        this.city=res.data;
                    }
                });
            },

            //翻译省市
            getDetailAddress(registeredProvince,registeredCity,registeredAddress){
                if(registeredProvince!="" && registeredCity!="" && registeredAddress !=""){
                    let province="";
                    let city="";
                    for(let i=0;i<this.province.length;i++){
                        if(this.province[i].value==registeredProvince){
                            province=this.province[i].label;
                        }
                    };
                    for(let i=0;i<this.city.length;i++){
                        if(this.city[i].value==registeredCity){
                            city=this.city[i].label;
                        }
                    };
                    return province+"/"+city;
                }else{
                    return '';
                }
            },

            // 查询自己的权限
            getRole() {
                //判断是管理员  全都可以操作
                if (this.$store.state.user.roles.toString().indexOf("ROLE_ADMIN") != -1) {
                    //非直营权限：新车：01；二手车：02；新车and二手车：03
                    this.businessTypeChannel = "03";
                    //直营权限：新车：01；二手车：02；新车and二手：03
                    this.ownBusinessTypeChannel = "03";
                    //页面跳转所需判断参数：新车
                    this.isNewCarRole="1";
                    //页面跳转所需判断参数：二手车
                    this.isOldCarRole="1";
                    console.log("我是管理员");
                } else {
                    //非直营角色判断
                    if ((this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_NEW_MANAGE_CHANNEL_DEVELOP") != -1 || this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_NEW_SEE_CHANNEL_DEVELOP") != -1)
                        && (this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_OLD_MANAGE_CHANNEL_DEVELOP") != -1 || this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_OLD_SEE_CHANNEL_DEVELOP") != -1)) {
                        // 说明当前用户非直营权限为：新车and二手车
                        this.businessTypeChannel = "03";
                        this.isNewCarRole="1";
                        this.isOldCarRole="1";
                        console.log("我是非直营新车、二手车");
                    }else if (this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_OLD_MANAGE_CHANNEL_DEVELOP") != -1 || this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_OLD_SEE_CHANNEL_DEVELOP") != -1) {
                        // 说明是二手车非直营管理
                        this.businessTypeChannel = "02";
                        this.isNewCarRole="0";
                        this.isOldCarRole="1";
                        console.log("我是非直营二手车");
                    }else if(this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_NEW_MANAGE_CHANNEL_DEVELOP") != -1 || this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_NEW_SEE_CHANNEL_DEVELOP") != -1){
                        // 说明是新车车非直营管理
                        this.businessTypeChannel = "01";
                        this.isNewCarRole="1";
                        this.isOldCarRole="0";
                        console.log("我是非直营新车");
                    }
                    //直营角色判断
                    if ((this.$store.state.user.roles.toString().indexOf("ROLE_OWN_NEW_MANAGE_CHANNEL_DEVELOP") != -1 || this.$store.state.user.roles.toString().indexOf("ROLE_OWN_NEW_SEE_CHANNEL_DEVELOP") != -1)
                        && (this.$store.state.user.roles.toString().indexOf("ROLE_OWN_OLD_MANAGE_CHANNEL_DEVELOP") != -1 ||this.$store.state.user.roles.toString().indexOf("ROLE_OWN_OLD_SEE_CHANNEL_DEVELOP") != -1)) {
                        //说明当前用户直营权限为：新车and二手车
                        this.ownBusinessTypeChannel = "03";
                        this.isNewCarRole="1";
                        this.isOldCarRole="1";
                        console.log("我是直营新车、二手车");
                    }else if(this.$store.state.user.roles.toString().indexOf("ROLE_OWN_NEW_MANAGE_CHANNEL_DEVELOP") != -1 ||this.$store.state.user.roles.toString().indexOf("ROLE_OWN_NEW_SEE_CHANNEL_DEVELOP") != -1){
                        //说明当前用户直营权限为：新车
                        this.ownBusinessTypeChannel = "01";
                        this.isNewCarRole="1";
                        this.isOldCarRole="0";
                        console.log("我是直营新车");
                    }else if(this.$store.state.user.roles.toString().indexOf("ROLE_OWN_OLD_MANAGE_CHANNEL_DEVELOP") != -1 || this.$store.state.user.roles.toString().indexOf("ROLE_OWN_OLD_SEE_CHANNEL_DEVELOP") != -1){
                        //说明当前用户直营权限为：二手车
                        this.ownBusinessTypeChannel = "02";
                        this.isNewCarRole="0";
                        this.isOldCarRole="1";
                        console.log("我是直营二手车");
                    }
                }
                this.searchForm.ownBusinessTypeChannel=this.ownBusinessTypeChannel;
                this.searchForm.businessTypeChannel = this.businessTypeChannel;
                this.searchForm.channelStatus="00";
                this.getChannelList();
            },

            getManage(){
                //判断是管理员  全都可以操作
                if (this.$store.state.user.roles.toString().indexOf("ROLE_ADMIN") != -1) {
                    //非直营权限：新车：01；二手车：02；新车and二手车：03
                    this.businessManage = "03";
                    //直营权限：新车：01；二手车：02；新车and二手：03
                    this.ownBusinessManage = "03";
                    //页面跳转所需判断参数：新车
                    this.isNewCarRole="1";
                    //页面跳转所需判断参数：二手车
                    this.isOldCarRole="1";
                    this.isManage="1";
                    console.log("我是管理员");
                } else {
                    //非直营角色判断
                    if (this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_NEW_MANAGE_CHANNEL_DEVELOP") != -1
                        && (this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_OLD_MANAGE_CHANNEL_DEVELOP") != -1)) {
                        // 说明当前用户非直营权限为：新车and二手车
                        this.businessManage = "03";
                        this.isNewCarRole="1";
                        this.isOldCarRole="1";
                        console.log("我是非直营新车、二手车");
                    }else if (this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_OLD_MANAGE_CHANNEL_DEVELOP") != -1) {
                        // 说明是二手车非直营管理
                        this.businessManage = "02";
                        this.isNewCarRole="0";
                        this.isOldCarRole="1";
                        console.log("我是非直营二手车");
                    }else if(this.$store.state.user.roles.toString().indexOf("ROLE_OTHER_NEW_MANAGE_CHANNEL_DEVELOP") != -1){
                        // 说明是新车车非直营管理
                        this.businessManage = "01";
                        this.isNewCarRole="1";
                        this.isOldCarRole="0";
                        console.log("我是非直营新车");
                    }
                    //直营角色判断
                    if (this.$store.state.user.roles.toString().indexOf("ROLE_OWN_NEW_MANAGE_CHANNEL_DEVELOP") != -1
                        && this.$store.state.user.roles.toString().indexOf("ROLE_OWN_OLD_MANAGE_CHANNEL_DEVELOP") != -1) {
                        //说明当前用户直营权限为：新车and二手车
                        this.ownBusinessManage = "03";
                        this.isNewCarRole="1";
                        this.isOldCarRole="1";
                        console.log("我是直营新车、二手车");
                    }else if(this.$store.state.user.roles.toString().indexOf("ROLE_OWN_NEW_MANAGE_CHANNEL_DEVELOP") != -1){
                        //说明当前用户直营权限为：新车
                        this.ownBusinessManage = "01";
                        this.isNewCarRole="1";
                        this.isOldCarRole="0";
                        console.log("我是直营新车");
                    }else if(this.$store.state.user.roles.toString().indexOf("ROLE_OWN_OLD_MANAGE_CHANNEL_DEVELOP") != -1){
                        //说明当前用户直营权限为：二手车
                        this.ownBusinessManage = "02";
                        this.isNewCarRole="0";
                        this.isOldCarRole="1";
                        console.log("我是直营二手车");
                    }
                }
            },
            afterArchive(){
                if (this.selectCount <= 0) {
                    this.$Message.warning("您还未选择需要推送的数据");
                    return;
                }
                let ids = [];
                this.selectList.forEach(function (e) {
                    ids.push(e.id);
                });
                let param={
                    channelIds:ids,
                };
                afterArchive(param).then(res => {
                    if (res.code === "0000") {
                        this.$Message.success("推送成功");
                        this.getChannelList();
                        this.selectCount=0;
                    }
                });
            }

        },
        created() {
            this.initDataDic();
        },
        mounted() {
            this.init();
        },
        watch: {
            '$route'(to,from){
                this.handleReset();
            }
        },
    };
</script>




<style scoped>
    .search .ivu-modal-body {
        padding: 16px;
        font-size: 12px;
        line-height: 1.5;
    }
    .search  .ivu-select-selected-value {
        height: 22px;
        line-height: 22px;
    }
    .search selected-value {
        display: block;
        height: 30px;
        line-height: 30px;
        font-size: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding-left: 8px;
        padding-right: 24px;
    }
    .search .ivu-input-with-suffix {
        padding-right: 32px;
    }
</style>
